<template>
  <div>
    <div class="title">
      <div class="title-div">
        <span>伍仁行,为你贴心服务</span>
        <button class="btn1" @click="jump">{{ login }}</button>
      </div>
    </div>
    <!-- 导航栏 -->
    <div class="nav">
      <div class="img">
        <img src="./images/logo.png" alt="" width="100%" height="100%" />
      </div>
      <div class="nav_list">
        <ul>
          <li class="frist" @click="pageone">首页</li>
          <li
            v-for="(item, index) in navdata"
            :key="index"
            @click="page(index)"
          >
            <div class="fun-div" ref="ha" v-show="item.fnDiv">功能未开放</div>
            <div>
              {{ item.cont }}
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
 
  data() {
    return {
      navdata: [
        { id: "1", cont: "关于我们", fnDiv: false },
        { id: "2", cont: "优优BABY", fnDiv: false },
        { id: "3", cont: "高端家政", fnDiv: false },
        { id: "4", cont: "管家服务", fnDiv: false },
        { id: "5", cont: "加盟", fnDiv: false },
      ],
       login: "登录/注册",
    };
  },
  watch: {
    login(val) {
        console.log(1111);
      val = localStorage.getItem("token");
      
      if (val != "false") {
        
        if (val == null) {
          this.login = "登录/注册";
 
        } else {
          this.login = "个人用户";

        }
      } else {
        this.login = "登录/注册";

      }
    },
  },
  methods: {
    page(i) {
      if (i == 0) {
        this.$router.push("/brief");
      }
      if (i >= 1) {
        let arr1 = this.$refs.ha;
        for (let j = 0; j < arr1.length; j++) {
          this.navdata[j].fnDiv = false;
          console.log(11111);
        }
        console.log(22222);
        this.navdata[i].fnDiv = true;
      }
    },
    jump() {
      var a = localStorage.getItem("token");
      if (a == "false") {
        console.log(1);
        this.$router.push({ path: "/about" });
      } else {
        if (a == null) {
          this.$router.push({ path: "/about" });
        } else {
          console.log(0);
          if (localStorage.getItem("type") == 1) {
            this.$router.push("/recommend");
          } else {
            this.$router.push("/order");
          }
        }
      }
    },
    pageone() {
      this.$router.push({ path: "/" });
    },
  },
  mounted(val) {
    if (this.a === "1") {
      this.login = "个人中心";
    } else {
      this.login = "登录";
    }
  },
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
  list-style: none;
  text-decoration: none;
  text-align: center;
}
/* 头部 */
.title {
  /* margin-top: -60px; */
  background-color: rgb(245, 84, 106);
  color: white;
  height: 60px;
  line-height: 60px;
}
.title-div {
  width: 80%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
}
.title-div > span {
  color: black;
  font-size: 20px;
}
.title-div > button {
  display: inline-block;
  width: 200px;
  color: black;
  height: 60px;
  border-radius: 10px;
  line-height: 30px;
  font-size: 20px;
  background-color: rgba(255, 255, 255, 0);
}
.btn1 {
  /* margin-right: 700px; */
  border: none;
}
.btn1:focus {
  outline: none;
}
/* .btn2 {
  margin-right: 200px;
} */
.nav {
  width: 80%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid transparent;
}

/* 导航栏 */
.img {
  width: 20%;
  margin-top: -120px;
}
.nav_list {
  width: 80%;
}
.nav_list > ul {
  display: flex;
  color: #999999;
  flex-direction: row;
  /* margin-left: -800px; */
  margin-top: 60px;
}
.fun-div {
  margin-top: -40px;
}
.nav_list > ul > li {
  margin-left: 20px;
  padding-bottom: 20px;
  font-size: 28px;
  margin-top: -20px;
  width: 200px;
  cursor: pointer;
}
.nav_list > ul > li:nth-of-type(2) {
  color: black;
}
.nav_list > ul > .frist {
  color: red;
}
.nav_list > ul > li:nth-of-type(2):hover {
  color: #aa8146;
  border-bottom: 2px solid #aa8146;
}
.nav_list > ul > .frist:hover {
  color: red;
  font-weight: bold;
}
</style>